package cn.edu.dgut.css.sai;

import cn.edu.dgut.css.sai.App;
import com.dgut.autoconfig.CustomProperties;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.test.context.ContextConfiguration;

@SpringBootTest

public class tests {
    @Autowired
    ApplicationEventMulticaster eventMulticaster;
    /*
     * 测试使用线程池异步发布事件
     * 观察终端的打印信息，并确定打印信息的线程名称是[task-xx],因为spring boot默认创建的线程池的名称前缀是task-
     * */
    @Test
    void testAsyncEventMulticaster() throws InterruptedException{
        eventMulticaster.multicastEvent(new App.NoticeEvent("东莞理工学院"));
        eventMulticaster.multicastEvent(new App.NoticeEvent("网安学院"));
        //睡眠单元测试主线程2.1秒，避免单元测试主线程结束时异步事件的线程还没有结束而报异常
        Thread.sleep(2100);
    }
}
